#ifndef SAVESETTINGS_H
#define SAVESETTINGS_H
//存储设置

#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
#include <QComboBox>
#include <QGridLayout>
#include <QCheckBox>
#include <QGroupBox>
#include <QStringList>
#include <QSettings>
#include <QMessageBox>
#include <QFileDialog>
#include <QCoreApplication>

namespace Ui {
class SaveSettings;
}

struct VideoConfig {
    QString ip;
    QString prefix;
    int port;
};
struct SplitConfig {
    quint32 msize;    //M大小
    quint32 secTime;  //时间多少s
};
// 配置数据结构体
struct SettingsData {
   quint32 mSize;   //存储文件大小上限

   // 文件存储上限
   int saveMaxNum;
   int deleteWayIndex;

   QString fileSavePath;

   SettingsData() {
       mSize = 0;
       saveMaxNum = 0;
       deleteWayIndex = 0;
       fileSavePath = "./data";
   }
   SettingsData(quint32 w_size, int w_saveMaxNum,int w_deleteWayIndex, QString w_fileSavePath){
       mSize = w_size;
       saveMaxNum = w_saveMaxNum;
       deleteWayIndex = w_deleteWayIndex;
       fileSavePath = w_fileSavePath;
   }
   SettingsData& operator=(const SettingsData& other) {
       if(this != &other) {
           mSize = other.mSize;
           saveMaxNum = other.saveMaxNum;
           deleteWayIndex = other.deleteWayIndex;
           fileSavePath = other.fileSavePath;
       }
       return *this;
   }
};

class SaveSettings : public QWidget
{
    Q_OBJECT

public:
    explicit SaveSettings(QWidget *parent = nullptr);
    ~SaveSettings();

    void sendSigToSaveData();   //发送数据到保存类的后端

    const SettingsData& getSettingsData(); //获取配置文件内容

private:
    Ui::SaveSettings *ui;

    SettingsData m_settingsData; //存储所有设置信息的变量
    QGridLayout *m_gridLayout;

//    QLabel *m_systemLogPathLabel;
//    QPushButton *m_systemLogPathButton;
//    QLineEdit *m_systemLogPathEdit;
//    QCheckBox *m_systemLogPathCheckBox;

    QLabel *m_fileSaveWay;   //文件存储方式
    QLabel *m_fileSaveNum;   //文件存储上限

    QComboBox *m_deleteWay;   //文件删除方式

    QCheckBox *m_exitAutoSave;  //退出自动保存

    QSpinBox *m_saveMaxNum;     //文件存储个数上线

    QLineEdit *m_saveWayValueLine;      //文件存储方式选择后

    QPushButton *m_saveParam;       //存储参数配置保存
    QPushButton *m_savePathPushButton; //save path
    QLineEdit *m_savePathLineEdit;  //saveLine show

    void setupLayout();     //设置布局

    void setupConnections();    //连接信号和槽

    void setControlValue();     //设置控件值

    void saveConfig();  // 保存配置到文件

    void loadConfig();  // 从文件加载配置
signals:
    void sigSettingsData(const SettingsData& settingsData);

};

#endif // SAVESETTINGS_H
